﻿using System;
using System.Collections.Generic;
using System.Text;

namespace XProject.Commons.TypeUtil.ConverterTypes
{
    public class DataTimeType : IConvertibility
    {
        private string dateformat = "yyyyMMdd HHmmss";
        #region IConvertibility 成员

        public object[] GetRegisterKeys()
        {
            return new object[] { typeof(DateTime) };
        }

        public object GetValue(string strValue)
        {
            if (strValue != null && strValue.Length == 15)
            {
                return DateTime.ParseExact(strValue, dateformat, System.Globalization.CultureInfo.CurrentCulture);
            }
            return null;
        }

        public string GetValueStr(object value)
        {
            return ((DateTime)value).ToString(dateformat);
        }

        #endregion
    }
}
